package org.example.blog.config;

import lombok.extern.slf4j.Slf4j;
import org.example.blog.enmus.ResultCodeEnum;
import org.example.blog.model.Result;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.nio.file.LinkOption;

@Slf4j
@RestControllerAdvice
public class ExceptionAdvice {
    @ExceptionHandler
    public Result handle(Exception e){
        log.error("发生异常，e：",e);
        return Result.fail(e.getMessage());
    }

    @ExceptionHandler
    public Result handle(UnsupportedOperationException e){
        log.error("发生异常，e：{}",e.getMessage());
        return Result.fail(ResultCodeEnum.PARAM_INVALID.getCode(),e.getMessage());
    }
    @ExceptionHandler
    public Result handle(MethodArgumentNotValidException e){
        log.error("参数校验不通过，e：{}",e.getMessage());
        return Result.fail(ResultCodeEnum.PARAM_INVALID.getCode(),e.getMessage());
    }
}
